package com.yueze.demo1.util;

import java.io.*;

/**
 * @author Administrator
 * @create 2020-07-28
 * 11:18
 * @desc
 **/
public class MyCopy {

    public static void save(String s1,String s2){
        try {
        // 文件输入流并进行缓冲
        FileInputStream inputStream = null;

            inputStream = new FileInputStream(new File(s1));

        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);

        // 文件输出流并进行缓冲
        FileOutputStream outputStream = new FileOutputStream(new File(s2));
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);

        // 缓冲数组
        // 大文件 可将 1024 * 2 改大一些，但是 并不是越大就越快
        byte[] bytes = new byte[1024 * 2];
        int len = 0;
        while ((len = inputStream.read(bytes)) != -1) {
            bufferedOutputStream.write(bytes, 0, len);
        }
        // 刷新输出缓冲流
        bufferedOutputStream.flush();
        //关闭流
        bufferedInputStream.close();
        bufferedOutputStream.close();
        inputStream.close();
        outputStream.close();
        } catch (Exception e) {
        e.printStackTrace();
    }
    }
}
